<?php
namespace Api\Controller;
use Think\Controller;
class ProMatchController extends Controller{
	public $psw='1qa2ws';
	public function index(){
		
		echo "Error:index";
	}
	protected function getJSONReturn($value){
		header("Content-Type: text/json");
		die(json_encode($value));
	}
	//返回对应的信息
	/*
	public function matchProPrice(){
		
		if(!IS_POST){
			//$this->checkKey();
			$rdata=$this->h87ReturnData();
			$rdata=json_decode($rdata,true);
			$this->getPro($rdata);
		}else{
			$error=array('code'=>0,'info'=>'出错');
			$this->getJSONReturn($error);
		}
		
	}
	// 检查key
	protected function checkKey(){
		$key=I('post.key');
		$key=trim($key);
		if(empty($key)){
			$error=array('code'=>0,'info'=>'key为空');
			$this->getJSONReturn($error);
		}
		if($key!=$this->psw){
			$error=array('code'=>0,'info'=>'key出错');
			$this->getJSONReturn($error);
		}else{
			return true;
		}
	}
	// 获取对应的信息
	protected function getPro($rda){
		$rError=array('code'=>0,'info'=>'ERROR');
		if($rda['code']=='success'){
			if(!empty($rda['data'])){
				$pList=array();
				foreach($rda['data'] as $k=>$v){
					$pList[]=$v['prodname'];
				}
				$pList=array_unique($pList);
				$rPda=array();
				if(!empty($pList)){
					$MP=M('product');
					$wh=array('prodname'=>array('in',$pList));
					$rPda=$MP->where($wh)->select();
				}
				
				if(!empty($rPda)){
					foreach( $rPda as $k=>$v){
						$rPda[$k]['price']=round($v['price'],2);
					}
					$rError=array('code'=>1,'data'=>$rPda);
				}else{
					$rError=array('code'=>0,'data'=>null);
				}
			}
		}
		$this->getJSONReturn($rError);
	}
	public function h87ReturnData(){
		$rdata=array("code"=>"success","data"=>array(array("specificatioinid"=>"1","prodname"=>"长条家具","price"=>"50.00","address"=>"广东","specificatioinname"=>"什么"),
													array("specificatioinid"=>"2","prodname"=>"家具2","price"=>"560.00","address"=>"广东","specificatioinname"=>"什么"),));
		return json_encode($rdata);
	}
	*/
	// 根据订单号放回家具类型
	public function reDataByOrderNo(){
		$orN=I('post.orderNo');
		$rda=$this->rDByON($orN);
		$this->getJSONReturn($rda);
	}
	//接口计算
	protected function rDByON($orderNo){
		$error=array('code'=>'0','info'=>'fail');
		if(!empty($orderNo)){
			// 接口计算
			$fur_nArr=array(array('prodid'=>1,'prodname'=>'衣柜（70CM)','price'=>70,'catname'=>'柜子','catid'=>1,"number"=>1),
						 array('prodid'=>2,'prodname'=>'长衣柜（100CM)','price'=>90,'catname'=>'柜子','catid'=>1,"number"=>1),
						 array('prodid'=>3,'prodname'=>'木椅子','price'=>90,'catname'=>'柜子','catid'=>1,"number"=>1));
			$totalP=0;
			foreach($fur_nArr as $k=>$v){
				$totalP=$totalP+($v['price']*$v['price']);
			}
			if(!empty($fur_nArr)){
				$error=array('code'=>1,'furnilist'=>$fur_nArr,'total'=>$totalP);
			}
		}
		return $error;
	}
	//返回家具信息
	public function reFurnitures(){
		$rData=$this->reProduct();
		$error=array('code'=>0,'info'=>'error');
		if(!empty($rData['flist'])){
			$error=array('code'=>1);
			$error=array_merge($error,$rData);
		}
		
		$this->getJSONReturn($error);
	}
	protected function reProduct(){
		$MP=M('product');
		$whe=array("prodid"=>array("egt",0));
		$prListT=$MP->where($whe)->select();
		$catArrList=array();
		foreach($prListT as $k=>$v){
			$catArrList[$v['catid']][]=$v;
		}
		$catArr=array();
		$catlistT=F('SYS/catList');
		$catlist=array();
		foreach($catlistT as $k=>$v){
			$catlist[]=$v;
		}
		$rData=array('catlist'=>$catlist,'flist'=>$catArrList);
		return $rData;
	}
}